package myJs.user

import myJs.Implicits._
import myJs.myPkg.jquery._
import myJs.tool.Tool
import org.scalajs.dom
import org.scalajs.dom.html.Canvas
import org.scalajs.dom.{Event, document}

import scala.scalajs.js
import scala.scalajs.js.Dynamic.{global => g}
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}

/**
 * Created by yz on 16/9/2021
 */
@JSExportTopLevel("ChangePassword")
object ChangePassword {

  @JSExport("init")
  def init = {
    bootStrapValidator
  }

  def bootStrapValidator = {
    val url = g.jsRoutes.controllers.UserController.accountCheck().url.toString
    val maxNumber = Double.MaxValue
    val dict: js.Dictionary[js.Any] = js.Dictionary(
      "feedbackIcons" -> js.Dictionary(
        "valid" -> "glyphicon glyphicon-ok",
        "invalid" -> "glyphicon glyphicon-remove",
        "validating" -> "glyphicon glyphicon-refresh",
      ),
      "fields" -> js.Dictionary(
        "password" -> {
          val info = "密码"
          js.Dictionary(
            "validators" -> js.Dictionary(
              "notEmpty" -> js.Dictionary(
                "message" -> s"${info}不能为空！"
              ),
            )
          )
        },
        "newPassword" -> {
          val info = "新密码"
          js.Dictionary(
            "validators" -> js.Dictionary(
              "notEmpty" -> js.Dictionary(
                "message" -> s"${info}不能为空！"
              ),
            )
          )
        },
        "newPasswordAgain" -> {
          val info = "再次确认新密码"
          js.Dictionary(
            "validators" -> js.Dictionary(
              "notEmpty" -> js.Dictionary(
                "message" -> s"${info}不能为空！"
              ),
              "identical" -> js.Dictionary(
                "field" -> "newPassword",
                "message" -> "两次密码不一样!"
              ),
            )
          )
        },
      )
    )
    $(s"#form").bootstrapValidator(dict)
  }


}
